<template>
  <div class="app-container">
    <el-alert :title="'收到' + newMessage + '条新消息'" type="info" close-text="关闭" description="消息说明"></el-alert>

    <el-card class="box-card">

      <div slot="header" class="clearfix">
        <span>收到的消息</span>
        <el-button style="float: right; padding: 3px 0; margin-right:10px;" type="text">刷新</el-button>
      </div>

      <el-collapse accordion>
        <el-collapse-item title="超级管理员列" name="1">
          <div v-for="item in principalMessageList">
            <el-divider></el-divider>
            <span style="color: #F08080;">{{ item.messageFrom }}</span>
            <el-button style="float: right; padding: 3px 0; margin-right:10px;" type="text"
              @click="showMessage(item)">查看</el-button>
          </div>
        </el-collapse-item>

        <el-collapse-item title="管理员列" name="2">
          <div v-for="item in superAdminMessageList">
            <el-divider></el-divider>
            <span style="color: #9A32CD;">{{ item.messageFrom }}</span>
            <el-button style="float: right; padding: 3px 0; margin-right:10px;" type="text"
              @click="showMessage(item)">查看</el-button>
          </div>
        </el-collapse-item>

        <el-collapse-item title="影院负责人列" name="3">
          <div v-for="item in principalMessageList">
            <el-divider></el-divider>
            <span style="color: #228B22;">{{ item.messageFrom }}</span>
            <el-button style="float: right; padding: 3px 0; margin-right:10px;" type="text"
              @click="showMessage(item)">查看</el-button>
          </div>
        </el-collapse-item>

      </el-collapse>
    </el-card>

    <el-card class="box-card" style="margin-top: 10px;">

      <div slot="header" class="clearfix">
        <span>发出的消息</span>
      </div>

      <el-collapse accordion>
        <el-collapse-item title="超级管理员列" name="1">
          <div v-for="item in superAdminList">
            <el-divider></el-divider>
            <span style="color: #F08080;">{{ item.targetName }}</span>
            <el-button style="float: right; padding: 3px 0; margin-right:10px;" type="text"
              @click="showSendMessageForm(item)">发消息</el-button>
          </div>
        </el-collapse-item>

        <el-collapse-item title="管理员列" name="2">
          <div v-for="item in adminList">
            <el-divider></el-divider>
            <span style="color: #9A32CD;">{{ item.targetName }}</span>
            <el-button style="float: right; padding: 3px 0; margin-right:10px;" type="text"
              @click="showSendMessageForm(item)">发消息</el-button>
          </div>
        </el-collapse-item>

        <el-collapse-item title="影院负责人列" name="3">
          <div v-for="item in principalList">
            <el-divider></el-divider>
            <span style="color: #228B22;">{{ item.targetName }}</span>
            <el-button style="float: right; padding: 3px 0; margin-right:10px;" type="text"
              @click="showSendMessageForm(item)">发消息</el-button>
          </div>
        </el-collapse-item>

      </el-collapse>
    </el-card>

    <el-dialog title="消息输入" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item :label="form.sendTarget">
          <el-input autocomplete="off" type="textarea"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="sendMessage">发送</el-button>
        <el-button @click="dialogFormVisible = false">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>
  
<script>

export default {

  data() {
    return {
      form: {
        sendTarget:'',
        sendMessageContent:''
      },
      dialogFormVisible: false,
      newMessage: 135,
      superAdminMessageList: [{
        messageFrom: '选项1',
        messageContent: '黄金糕'
      }, {
        messageFrom: '选项2',
        messageContent: '双皮奶'
      }, {
        messageFrom: '选项3',
        messageContent: '蚵仔煎'
      }],

      adminMessageList: [{
        messageFrom: '选项1',
        messageContent: '黄金糕'
      }, {
        messageFrom: '选项2',
        messageContent: '双皮奶'
      }, {
        messageFrom: '选项3',
        messageContent: '蚵仔煎'
      }],

      principalMessageList: [{
        messageFrom: '选项1',
        messageContent: '黄金糕'
      }, {
        messageFrom: '选项2',
        messageContent: '双皮奶'
      }, {
        messageFrom: '选项3',
        messageContent: '蚵仔煎'
      }],

      superAdminList: [{
        targetName: '甲醛'
      }],

      adminList: [{
        targetName: '草莓熊'
      }, {
        targetName: '猪猪侠'
      }],

      principalList: [{
        targetName: '万掌门'
      },
      {
        targetName: '时掌门'
      },
      {
        targetName: '飞掌门'
      }]

    }
  },
  methods: {
    showMessage(item) {
      this.$alert(item.messageContent, item.messageFrom, {
        confirmButtonText: '确定',
        callback: _ => {
          this.$message({
            type: 'info',
            message: `已阅一条消息`
          });
        }
      });
    },
    showSendMessageForm(item) {
      this.form.sendTarget = item.targetName
      this.dialogFormVisible = true  
    },
    sendMessage() {
      this.dialogFormVisible = false
      this.$message({
        type: 'success',
        message: `已发送一条消息`
      })
    }
  },
  watch: {

  },
  mounted() {

  }
};
</script>
  
  